package cn.may.service.impl;

import cn.may.exception.StudentException;
import cn.may.repository.student.StudentDao;
import cn.may.domain.student.Student;
import cn.may.service.StudentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mayuanbao
 * @date 2019-06-02 10:57
 */
@Service(value = "studentService")
@Transactional(rollbackFor = Exception.class)
public class StudentServiceImpl implements StudentService {
    @Resource(name = "studentDao")
    StudentDao studentDao;

    @Override
    public List<Student> findAll() {
        return studentDao.findAll();
    }


    @Override
    public Student addStudent(Student student) {
        return studentDao.save(student);
    }

    @Override
    public Student findByName(String name) {
        return studentDao.findByName(name);
    }

    @Override
    public Student getById(Integer id) throws StudentException {
        /*Integer age = student.getAge();
        if (age < 10) {
            throw new StudentException(ResultEnum.PRIMARY_SCHOOL);
        }else if (age >=10 && age <16) {
            throw new StudentException(ResultEnum.MIDDLE_SCHOOL);
        }else {
//            throw new StudentException(102, "你在上高中");
        }*/
        return studentDao.findById(id);
    }
    @Override
    public int deleteById(Integer id){return studentDao.deleteById(id);}
}
